package com.xiaoyu.lanling.feature.im.provider

import `in`.srain.cube.concurrent.SimpleTask
import com.xiaoyu.im.datamodel.exception.IMException
import com.xiaoyu.im.request.MessageRequest
import com.xiaoyu.lanling.common.Constant.From.CHAT
import com.xiaoyu.lanling.feature.coin.activity.CoinRechargeDialogFragment
import com.xiaoyu.lanling.feature.coin.activity.CoinRechargeWithFirstChargeDialogFragment
import com.xiaoyu.lanling.feature.im.request.flow.FailureAction

object CustomIMExceptionProcessor {

    fun process(request: MessageRequest) {
        when (IMException.getIMExceptionCode(request.throwable)) {
            FailureAction.CODE_COIN_NOT_ENOUGH -> showCoinRechargeDialog()
            FailureAction.CODE_COIN_NOT_ENOUGH_WITH_FIRST_CHARGE -> showCoinChargeWithFirstCharge()
        }
    }

    private fun showCoinRechargeDialog() {
        SimpleTask.post {
            CoinRechargeDialogFragment.show(CHAT)
        }
    }

    private fun showCoinChargeWithFirstCharge() {
        SimpleTask.post {
            CoinRechargeWithFirstChargeDialogFragment.show()
        }
    }
}